<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>客户采纳方案管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		html, body {overflow-y:auto;}
		#contentTable{margin-left: 0px;}
		#searchForm .ui-select{
			display:inline-block;vertical-align: middle;width:240px;
		}
	</style>
	<script type="text/javascript">
		global.loginPassword = "${fns:getLoginPw()}";
		$(document).ready(function() {	
			$('.select_status').change(function(){ 
				var id = $(this).children('option:selected').val(); 
				var text = $(this).children('option:selected').html(); 
				var selectId = $(this).attr("id");
				if(id == "0") {
					return;
				}
				var submit = function () {
			    	var url = "${ctx}/expert/customerSolution/status?id="+ selectId +"&newStatus=" + id;
			    	jQuery.ajax({  
				          type : 'GET',  
				          url : url,  
				          success : function(data) { 
				        	 var time = new Date().Format("yyyy-MM-dd");
				        	 $("#time-" + selectId).html(time);
				        	 $("#status-" + selectId).html(text);
				        	 if(id == "1"){
				        	  	$("#xumai-" + selectId).html('不可续买');
				        	 }
				        	 showTip("状态更改成功");
				          },  
				          error : function(data) {  
				          }  
				    });
				};
				var cancle = function () {
				    $("#"+ selectId +" option[value='0']").attr("selected",true);
				    $("#"+ selectId).selectmenu('refresh');
				};
				var confirm = function () {
				  global.confirm("是否要改变方案状态?", submit, cancle);
				};
				loginPasswordPopup(confirm);
			});
			if(global.isMobile()) {
				$("#btnExport").parent().css("display", "none");
			} else {
				$("#btnExport").click(function(){
		 			global.confirm("确认要导出方案吗？", exportExcel);
				});
			}
			
			$('#status').change(function(){
				var status = $(this).children('option:selected').val();
				 
			});
			addParentPageNo();
		});
		
		function addParentPageNo() {
			var id = '${customerExamId}';
			var pageNo = 1;
			if(id != "" && sessionStorage.parentPageNo) {
				pageNo = sessionStorage.parentPageNo;
			}
			var href = "${ctx}/expert/customerExam/resultList/?pageNo=" +pageNo + "&currentSelectId=" +id;
			$("#return").attr("href", href);
		}
		function exportExcel(){
			var url = "${ctx}/expert/customerSolution/export?status="+ $("#status").val() +"&customerName=" + $("#customerName").val();
			window.location.href = url;
		}
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
</head>
<body>
<div class="icon-buttons">
	<a id="return" data-role="button" data-inline="true" data-icon="back" data-iconpos="notext"  href="">返回</a>
</div>
<form:form id="searchForm" modelAttribute="customerSolution" action="${ctx}/expert/customerSolution/managerList" method="post">
	<label>状态：</label>&nbsp;
	<select id="status" name="status">   
	 <option value="-2">全部</option>   
	  <c:forEach var="map" items="${fns:getDictMap('customerSolution_status')}">   
	 	<c:if test="${status == map.key}">
	 		<option value='${map.key}' selected="selected">  
	  			${map.value}  
			</option>   
	 	</c:if>
	 	<c:if test="${status != map.key}">
	 		<option value='${map.key}'>  
	  			${map.value}  
			</option>   
	 	</c:if>
	 </c:forEach>   
	</select> 
	<label>顾客姓名：${customerName}</label>&nbsp;
	<c:if test="${not empty list}">
	<input id="btnExport" data-inline="true" type="button" value="导出"/>&nbsp;&nbsp;&nbsp;&nbsp;
	</c:if>
</form:form>
<tags:message content="${message}"/>
<table id="contentTable" data-role="table" class="ui-responsive table-stroke">
	<thead><tr><th>方案名称</th><th>顾客姓名</th><th>开始日期</th><th>理论结束日期</th><th>实际结束日期</th><th>当前状态</th><th>续买</th></tr></thead>
	<tbody>
	<c:forEach items="${list}" var="customerSolution">
		<tr>
			<td>${customerSolution.solutionFace.name}</td>
			<td>${customerSolution.customerExam.customer.name}</td>
			<td>${fns:formatDate(customerSolution.customerExam.exam_time, "yyyy-MM-dd")}</td>
			<td>${fns:formatDate(customerSolution.plan_end_date, "yyyy-MM-dd")}</td>
			<td id="time-${customerSolution.id}">${fns:formatDate(customerSolution.real_end_date, "yyyy-MM-dd")}</td>
			<td id="status-${customerSolution.id}">
				<c:if test="${customerSolution.status != 0}">
					${fns:getDictLabel(customerSolution.status, 'customerSolution_status', '')}
				</c:if>
   				<c:if test="${customerSolution.status == 0}">
    				<select class="select_status" name="status" id="${customerSolution.id}">   
    					<option value='0'>正在进行</option> 
					 	<option value='1'>正常结束</option> 
					 	<option value='2'>提前终止</option>    
					</select> 
				</c:if>
			</td>
			<td id="xumai-${customerSolution.id}">
				<c:if test="${customerSolution.status == 1||customerSolution.status == 2}">
					不可续买
				</c:if>
				<c:if test="${customerSolution.status == 0}">
					<a data-role="button" data-inline="true" href="${ctx}/expert/customerSolutionAndProduct/detail?customerSolutionId=${customerSolution.id}&target=buy">续买</a>
				</c:if>
			</td>
		</tr>
	</c:forEach>
	</tbody>
</table>
</body>
</html>
